#!/usr/bin/python
# -*- coding: UTF-8 -*-

#! encoding = utf-8

import os, requests
import platform
 
def reportServer(_type, params):
    urls = {
        "userinfo": "/userinfo"
    }
    url="http://localhost:7788" + urls[_type]
    response = requests.get(url=url, params=params)

def isWindowsSystem():
    return 'Windows' in platform.system()
 
def isLinuxSystem():
    return 'Linux' in platform.system()

def get_phone_list():
    """ 获得已连接的设备列表 """
    print("正在获取设备列表")
    devices = []
    ret = os.popen("adb devices")
    device_list = ret.read().strip("\n\n").split("\n")
    del device_list[0]

    for device in device_list:
        dev_status = device.split("\t")
        dev = dev_status[0].strip() # 手机序列号
        stat = dev_status[1].strip() # 设备状态
        # 排除 IP 地址，仅使用 ID 操作
        if ":" not in dev and stat=='device':
            devices.append(dev)

    if len(devices) == 0:
        exit("没有获取到设备")

    print('共获取到 {} 个设备'.format(len(devices)))
    return devices
    return [devices[0]]